package cn.jeefast.modules.platform.controller;


import cn.jeefast.common.entity.MbResearchStep;
import cn.jeefast.common.entity.MbResearchStrpDataTemplate;
import cn.jeefast.common.utils.R;
import cn.jeefast.modules.platform.service.MbResearchStep1Service;
import cn.jeefast.modules.platform.service.MbResearchStrpDataTemplate1Service;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import cn.jeefast.common.base.BaseController;

import java.util.List;

/**
 * <p>
 * 研究阶段 前端控制器
 * </p>
 *
 * @author theodo
 * @since 2020-01-06
 */
@RestController
@RequestMapping("/mbResearchStep")
@CrossOrigin
public class MbResearchStep1Controller extends BaseController {

    @Autowired
	private MbResearchStep1Service researchStepService;
    @Autowired
    private MbResearchStrpDataTemplate1Service mbResearchStrpDataTemplate1Service;

    /**
     * 研究阶段ID
     * @param resId
     * @return
     */
    @RequestMapping("/list")
    public R list(Long resId){
        EntityWrapper ew = new EntityWrapper();
        ew.eq("res_id",resId);
        ew.orderBy("step_id",true);
        List<MbResearchStep> list = researchStepService.selectList(ew);
        for (MbResearchStep m:list) {
            MbResearchStrpDataTemplate mbResearchStrpDataTemplate = mbResearchStrpDataTemplate1Service.selectById(m.getTempId());
            m.setTempName(mbResearchStrpDataTemplate.getTempName());
        }
        return R.ok().put("data",list);
    }


    /**
     * 删除研究阶段
     * @param stepId
     * @return
     */
    @RequestMapping("/delete")
    public R delete(Long stepId){
        researchStepService.deleteById(stepId);
        return R.ok();
    }

    /**
     * 添加或修改研究阶段
     * @param researchStep
     * @return
     */
    @RequestMapping("/addOrSave")
    public R addOrSave(MbResearchStep researchStep){
        return researchStepService.addOrSave(researchStep);
    }

    /**
     * 研究阶段详情
     * @param id
     * @return
     */
    @RequestMapping("/detail")
    public R detail(Long id){
        MbResearchStep mbResearchStep = researchStepService.selectById(id);
        return R.ok().put("data",mbResearchStep);
    }
}